var vm = new Vue({
    el:"#app",
    data(){
        return {
            //初始化信息
            Store:'',

            //仓库
            wareHouses:[],
            //经销商
            Dealers:[],
            //搜索条件
            queryForm:{
                DealerNo:'',
                ProductName:'',
                WarehouseNo:'',
                Type:'',
                InNo:'',
                Store:''
            },
            KCInfoModel: false, //库存明细弹框
            //搜索结果
            columns1: [
                {
                    type: 'index',
                    title: '序号',
                    width:46,
                    align: 'center',
                },
                {
                    title: '入库编号',
                    key: 'InNo',
                    align: 'center',
                },
                {
                    title: '入库类型',
                    key: 'Type',
                    align: 'center',
                    render:(h, params)=>{
                        var isShow='';
                        if (params.row.Type==1){
                            isShow = "调拨入库";
                        }
                        if (params.row.Type==0){
                            isShow = "采购入库";
                        }
                        return h('span', isShow)
                    }
                },
                {
                    title: '店面',
                    key: 'Store',
                    align: 'center',
                },
                {
                    title: '经销商名称',
                    key: 'dalerName',
                    align: 'center',
                    render:(h,params) => {
                        if(params.row.dalerName==''||params.row.dalerName==null){
                            return h("span","-");
                        }else{
                            return h("span",params.row.dalerName);
                        }
                    }
                },
                {
                    title: '产品名称',
                    key: 'ProductName',
                    align: 'center',
                },
                {
                    title: '数量',
                    key: 'ProductNumber',
                    align: 'center',
                },
                {
                    title: '剩余数量',
                    key: 'RestNumber',
                    align: 'center',
                },
                {
                    title: '单价',
                    key: 'ProductPrice',
                    align: 'center',
                    width:100,
                    render:(h,params) => {
                        if(params.row.ProductPrice==''||params.row.ProductPrice==null){
                            return h("span","-");
                        }else{
                            return h("span",params.row.ProductPrice);
                        }
                    }
                },
                {
                    title: '仓库',
                    key: 'warehouseName',
                    align: 'center',
                },
                {   title: '操作',
                    key: 'action',
                    align: 'center',
                    width:150,
                    render: (h, params) => {
                        return h('div', [
                            h('a', {
                                style: {
                                    marginRight: '5px',
                                    border : '0',
                                    fontSize: '14px',
                                },
                                on: {
                                    click: () => {
                                        var InNo = params.row.InNo;
                                        this.queryInventoryInfo(InNo)
                                    }
                                }
                            },'明细')
                        ])
                    }
                }
            ],
            data1: [],
            rkTotal:0,
            rkCurrent:1,
            rkPageSize:15,
            // 选择库存明细弹框
            columns2: [
                {
                    type: 'index',
                    title: '序号',
                    width:46,
                    align: 'center',
                },
                {
                    title: '出库编号',
                    key: 'OutNo',
                    align: 'center',
                },
                {
                    title: '出库类型',
                    key: 'DocType',
                    align: 'center',
                    render:(h,params) => {
                        if(params.row.DocType=='1'){
                            return h("span","赠品出库");
                        }else if(params.row.DocType=='2'){
                            return h("span","赠品退货");
                        }else if(params.row.DocType=='3'){
                            return h("span","调拨出库");
                        }else if(params.row.DocType=='4'){
                            return h("span","采购退货");
                        }
                    }
                },
                {
                    title: '调拨状态',//已调拨、未调拨
                    key: 'DbFlag',
                    align: 'center',
                    render:(h,params) => {
                        if(params.row.DbFlag=='0'){
                            return h("span","未调拨");
                        }else if(params.row.DbFlag=='1'){
                            return h("span","已调拨");
                        }else{
                            return h("span","-");
                        }
                    }
                },
                {
                    title: '入库方',
                    key: 'OutUser',
                    align: 'center',
                },
                {
                    title: '销售票号',
                    key: 'UserDocNo',
                    align: 'center',
                    render:(h,params) => {
                        if(params.row.UserDocNo==''||params.row.UserDocNo==null){
                            return h("span","-");
                        }else{
                            return h("span",params.row.UserDocNo);
                        }
                    }
                },
                {
                    title: '展位编号',
                    key: 'ZwNo',
                    align: 'center',
                    render:(h,params) => {
                        if(params.row.ZwNo==''||params.row.ZwNo==null){
                            return h("span","-");
                        }else{
                            return h("span",params.row.ZwNo);
                        }
                    }
                },
                {
                    title: '产品名称',
                    key: 'ProductName',
                    align: 'center',
                },
                {
                    title: '出库数量',
                    key: 'OutNumber',
                    align: 'center',
                    width:80
                },
                {
                    title: '出库仓库',
                    key: 'WarehouseName',
                    align: 'center',
                },
                {
                    title: '经手人',
                    key: 'InputMan',
                    align: 'center',
                    width:80
                },
                {
                    title: '出库时间',
                    key: 'CreateTime',
                    align: 'center',
                    width:95
                }
            ],
            data2: [],
            ckTotal:0,
            ckCurrent:1,
            ckPageSize:15,
        }
    },
    created(){
        this.initThisPage();
        this.getDealer();
        this.getWh();
    },
    methods:{
        ok () {
        },
        cancel () {
        },
        rkbeforequerytable(current){
            var self = this;
            self.rkCurrent = current;
            self.queryIn();
        },
        //搜索
        queryIn(){
            var self = this;
            this.queryForm.Store=this.Store;
            var rkTotal = 0;
            var rkCurrent = self.rkCurrent;
            var rkPageSize = self.rkPageSize;
            var jsondata = this.queryForm;
            jsondata.rkCurrent = rkCurrent;
            jsondata.rkPageSize = rkPageSize;
            var data_json = JSON.stringify(jsondata);

            $.ajax({
                url: "./goInBound/queryAllInBound", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json", //返回格式为json
                data: data_json, //参数值
                type: "POST", //请求方式
                headers : {
                    'Content-Type' : 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    self.data1 = data.ResultList;
                    rkTotal = data.rkTotal;
                    self.rkTotal = rkTotal;
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function(data) {

                }
            });
        },
        //查询库存明细
        ckbeforequerytable(current){
            var self = this;
            self.ckCurrent = current;
            self.queryInventoryInfo();
        },
        queryInventoryInfo(InNo){
            var self = this;
            var ckCurrent = self.ckCurrent;
            var ckPageSize = self.ckPageSize;
            var jsondata = {"InNo":InNo,"ckCurrent":ckCurrent,"ckPageSize":ckPageSize};
            var data_json = JSON.stringify(jsondata);
            $.ajax({
                url: "./goOutBound/queryAllOutBound", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json", //返回格式为json
                data: data_json, //参数值
                type: "POST", //请求方式
                headers : {
                    'Content-Type' : 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    self.data2 = data.ResultList;
                    self.ckTotal = data.ckTotal;
                    self.KCInfoModel = true;
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function(data) {

                }
            });
        },
        initThisPage(){
            var self = this;
            $.ajax({
                url: "./goLogin/initIndexPage", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                async:false,
                dataType: "json", //返回格式为json
                type: "GET", //请求方式
                processData: false, //对表单data数据是否进行序列化
                contentType: false, //dataType设置你收到服务器数据的格式
                headers: {
                    'Content-Type': 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    if(data.Status==0){
                        window.location.href="../../login.html";
                    }else{
                        if(data.Store=="运营管理中心"){
                            self.Store = data.Store;
                            $("#QueryStoreIsOrNot").attr("style","");
                        }else{
                            self.Store = data.Store;
                            self.queryForm.Store = data.Store;
                            $("#QueryStoreIsOrNot").attr("style","display:none");
                        }
                    }
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function() {}
            });
        },
//获取仓库
        getWh(){
            var jsondata = {}
            var data_json = JSON.stringify(jsondata);
            var vueThis = this;
            $.ajax({
                url: "./goWh/queryWhByParm", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json", //返回格式为json
                data: data_json, //参数值
                type: "POST", //请求方式
                headers : {
                    'Content-Type' : 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    vueThis.wareHouses=data.ResultList;
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function(data) {

                }
            });
        },
        //获取经销商
        getDealer(){
            var jsondata = {}
            var data_json = JSON.stringify(jsondata);
            var vueThis = this;
            $.ajax({
                url: "./goJxs/queryAllJxs", //请求的url地址
                xhrFields: {
                    withCredentials: true
                },
                dataType: "json", //返回格式为json
                data: data_json, //参数值
                type: "POST", //请求方式
                headers : {
                    'Content-Type' : 'application/json'
                },
                beforeSend: function() {
                    //请求前的处理
                },
                success: function(data) {
                    vueThis.Dealers=data.ResultList;
                },
                complete: function() {
                    //请求完成的处理
                },
                error: function(data) {

                }
            });
        },
        //手机号验证
        isPoneAvailable(str) {
            var myreg=/^[1][3,4,5,7,8][0-9]{9}$/;
            if (!myreg.test(str)) {
                return false;
            } else {
                return true;
            }
        },
        //uuid
        uuid(len, radix) {
            var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'.split('');
            var uuid = [], i;
            radix = radix || chars.length;

            if (len) {
                // Compact form
                for (i = 0; i < len; i++) uuid[i] = chars[0 | Math.random()*radix];
            } else {
                // rfc4122, version 4 form
                var r;

                // rfc4122 requires these characters
                uuid[8] = uuid[13] = uuid[18] = uuid[23] = '-';
                uuid[14] = '4';

                // Fill in random data. At i==19 set the high bits of clock sequence as
                // per rfc4122, sec. 4.1.5
                for (i = 0; i < 36; i++) {
                    if (!uuid[i]) {
                        r = 0 | Math.random()*16;
                        uuid[i] = chars[(i == 19) ? (r & 0x3) | 0x8 : r];
                    }
                }
            }

            return uuid.join('');
        }
    }
})